<template>
	<div style="padding:0px;">
		<el-form :model="dialogForm"  ref="dialogForm" :rules="rules" :label-width="formLabelWidth">
		<el-card class="box-card">
		  <div slot="header" class="clearfix">
		    <span style="line-height: 30px;">订单信息</span>
		  </div>
		    <div  class="text item">
		    	<el-form-item label="订单号"  >
			      <el-input  v-model="dialogForm.orderNumber" auto-complete="off" disabled ></el-input>
			    </el-form-item>
			  	<el-form-item label="经销商名称"   id="aaa" >
			      <el-input v-model="dialogForm.dealerName" auto-complete="off"  disabled></el-input>
			    </el-form-item>
			    <el-form-item label="汽车车型"   >
			      <el-input v-model="dialogForm.carName" auto-complete="off" disabled></el-input>
			    </el-form-item>
			    <el-form-item label="汽车数量"   >
			      <el-input v-model="dialogForm.amount" auto-complete="off" disabled></el-input>
			    </el-form-item>
			    <el-form-item label="原车架号" >
			      <el-input v-model="dialogForm.oldVin" auto-complete="off" disabled></el-input>
			    </el-form-item>
			</div>
		</el-card>
		<el-card class="box-card" style="margin-top:15px;">
		  <div slot="header" class="clearfix">
		    <span style="line-height: 30px;">变更信息</span>
		  </div>
		  <div  class="text item">
			  	<el-form-item label="图片信息" >
			      <qiniu :qiniuImage="qiniuImage"  :packJson="packJson" :id="qiniuImage.id" :canDelete="dialogSendData.isAdd"></qiniu>
			    </el-form-item>
			    <el-form-item label="新车架号" >
			      <el-input type="textarea" :rows=3 v-model="dialogForm.vin" auto-complete="off" :disabled="!dialogSendData.isAdd"></el-input>
			    </el-form-item>
			    <el-form-item label="变更原因" >
			      <el-input type="areatext" v-model="dialogForm.vinChangeReason" auto-complete="off" :disabled="!dialogSendData.isAdd"></el-input>
			    </el-form-item>
			</div>
		</el-card>
		
		<div style="text-align:right;margin-top:15px;">
			 <el-button @click="returnBack">返 回</el-button>
			 <el-button  v-if="dialogSendData.isAdd" type="primary" @click="submitConfirmForm('dialogForm')">提 交</el-button>
		</div>
		</el-form>
	</div>
</template>
<script>
    import qiniu  from '@/views/qiniu/upload';
    import agentHttp from '@/utils/agentHttp.js'
	export default{
		created(){
   			this.selectData();
        },
		props:['dialogSendData','tableData'],
		components:{qiniu },
		data(){
			return{
				formLabelWidth:'170px',
				//弹窗或者查看页面信息
		        dialogForm:{
		        },
		        rules: {
		        },
		        //七牛图片上传
		        qiniuImage:{
		        	id:"qiniuImage", //图片预览的id   
		        	image_uri:[],    //图片上传的列表  只含有url地址
		        },
		        packJson:{
					maxLength:50,   //最大图片数量
					accept:"",//image/gif,image/jpeg,image/jpg,image/png如果是这些，可以不传此参数
					size:4    //图片大小  单位兆
				}
			}
		},methods:{
			returnBack(){
				this.dialogSendData.dialogFormVisible=false;
			},
			submitConfirmForm(formName){
                this.$refs[formName].validate((valid) => {
		          if (valid) {
		            this.editData();//修改
		          } else {
		            console.log('error submit!!');
		            return false;
		          }
		        });
			},
			//初始化数据
		    selectData(){
		        agentHttp.get('adminApi/admin/vin_change/view/'+this.dialogSendData.id).then((data)=>{	
		            if(data.success){
		            	this.dialogForm=data.data;        	
		            	this.qiniuImage.image_uri=data.data.pic.split(',');
		            	if(data.data.oldVin==null||data.data.oldVin==''){		            		
		            		this.dialogForm.oldVin = data.data.vin;
		            		this.dialogForm.vin = "";		            		
		            	}            	
		            }
		        }) 
		    },
		    //修改提交
		    editData(){
		    	this.dialogForm.pic = this.qiniuImage.image_uri.join(",");
		        agentHttp.putJson('adminApi/admin/vin_change/update',this.dialogForm).then((data)=>{
		            if(data.success){
		            	setTimeout(()=>{
		            		this.dialogSendData.dialogFormVisible=false;
		            	},500)  
		            	this.$emit('refreshSeachData',null);
		            	this.$message.success(data.data||"修改成功");		            	
		            } 
		        }) 
		    },
		}
	};
	
</script>